<template>
  <div class="box">
    <el-form ref="ruleForm" :model="ruleForm" status-icon :rules="rules">
      <img class="titleimg" src="http://likede2-admin.itheima.net/img/logo.595745bd.png" alt="">
      <el-form-item prop="loginName">
        <!-- 手机icon图标 -->
        <el-input v-model="ruleForm.loginName" autocomplete="off" placeholder="请输入用户名">
          <template slot="prepend">
            <i class="el-icon-mobile" />
          </template>
        </el-input>

      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="ruleForm.password" autocomplete="off" show-password placeholder="请输入密码">
          <template slot="prepend">
            <i
              class="el-icon-lock"
            />
          </template>
        </el-input>
      </el-form-item>
      <el-form-item prop="test">
        <el-input v-model="ruleForm.code" placeholder="请输入验证码">
          <template slot="prepend">
            <i
              class="el-icon-check"
            />
          </template>
          <!-- 图片验证码 -->
          <template slot="append">
            <img :src="src" alt="" class="imgtext" @click="changeFn">
          </template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getTest } from '@/api/table'
export default {
  data() {
    return {
      ruleForm: {
        loginName: 'admin',
        password: 'admin',
        code: '',
        clientToken: Date.now(),
        loginType: 0
      },
      src: '',
      rules: {
        loginName: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { pattern: /^\w{5,16}$/, trigger: 'blur', message: '密码为5-16位' }
        ],
        code: [
          { required: true, trigger: 'blur', message: '请输入验证码' }
        ]
      }
    }
  },
  created() {
    console.log(process.env.VUE_APP_BASE_API)
    this.getimg()
  },
  methods: {
    async submitForm() {
      this.$refs.ruleForm.validate()
      await this.$store.dispatch('user/login', this.ruleForm)
      this.$router.push('/')
    },
    changeFn() {
      this.getimg()
    },
    async getimg() {
      const res = await getTest(this.ruleForm.clientToken)
      console.log(res)
      this.src = window.URL.createObjectURL(res)
      console.log(this.src)
    }
  }
}
</script>

<style>
.box{
      position: relative;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-image: url(http://likede2-admin.itheima.net/img/background.be4fae7d.png);
    background-repeat: no-repeat;
    background-size: cover;
}
.titleimg{
    position: absolute;
    width: 96px;
    height: 96px;
    top: -46px;
    left: 50%;
    margin-left: -48px;
}
.imgtext{
  height: 100%;
}
.el-input-group__prepend{
  background-color: #fff;

}
/* .el-input{
  height: 40px;
} */
.el-input__inner{
height: 60px;
}
.el-form{
 position: absolute;
    width: 518px;
    height: 400px;
    top: 50%;
    left: 50%;
    margin-top: -194px;
    margin-left: -259px;
    padding: 76px 35px 0;
    background: #fff;
     border-radius: 10px;
      box-shadow: 0 3px 70px 0 rgb(30 111 72 / 35%);
}
.el-button{
width: 448px;
height: 50px;
}

</style>
